package com.example.design.stream;

import java.util.Map;
import java.util.UUID;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Function;
import java.util.stream.Collectors;
import java.util.stream.LongStream;

/**
 * @Description TODO
 * @date 2023/1/5 16:44
 * @Author liuzhihui
 * @Version 1.0
 */
public class StreamTestDemo {
    public static void main(String[] args) {
        Map data = getData(10);
        System.out.println();

    }

    private static Map getData(int count) {
        return LongStream
                //返回从1(包括)到count(包括)的LongStream
                .rangeClosed(1, count)
                // LongStream转为stream
                .boxed()
                .collect(Collectors.toMap(
                        // key
                        i -> UUID.randomUUID().toString(),
                        // value,返回一个输出跟输入一样的Lambda表达式对象，等价于形如t -> t形式的Lambda表达式
                        Function.identity(),
                        // key重复，取01
                        (o1, o2) -> o1,
                        // 控制生成什么类型的map
                        ConcurrentHashMap::new
                        )
                );
    }
}
